package org.darcy.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import lombok.extern.slf4j.Slf4j;
import net.sf.ehcache.CacheManager;
import net.sf.ehcache.config.CacheConfiguration;

/**
 * Ehcache 缓存配置
 */
@Configuration
@Slf4j
public class EhcacheConfig {

	@Bean
	public CacheManager cacheManager() {
		log.info("创建ehcache CacheManager");
		
		CacheConfiguration defaultCache = new CacheConfiguration();
		defaultCache.setMemoryStoreEvictionPolicy("LRU");
		defaultCache.setMaxEntriesLocalHeap(1000);

		CacheConfiguration mycache = new CacheConfiguration();
		mycache.setName("mycache");
		mycache.setMemoryStoreEvictionPolicy("LRU");
		mycache.setMaxEntriesLocalHeap(1000);

		net.sf.ehcache.config.Configuration config = new net.sf.ehcache.config.Configuration();
		config.setDefaultCacheConfiguration(defaultCache);
		config.addCache(mycache);

		return net.sf.ehcache.CacheManager.newInstance(config);
	}

}